Repository navigation
Conversation
`nested_case_when` panics when it is given no WHEN/THEN pairs or more pairs than fit in a `u32`. Callers that build a CASE from user or query input had to repeat both checks or wrap the call to turn the panics into errors. Add `try_nested_case_when`, which returns an error in both cases, and have `nested_case_when` delegate to it with `vortex_expect`, as the `bound_*` constructors already do. Fixes vortex-data#11425 Signed-off-by: Vincent <1729065730@qq.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nested_case_whenpanics when it is given no WHEN/THEN pairs or more pairs than fit in au32. Callers that build aCASEfrom user or query input (for example branches translated from SQL) had to repeat both checks before calling it, or wrap it to turn the panics into errors.Changes
try_nested_case_when(when_then_pairs, else_value) -> VortexResult<Expression>invortex-array/src/expr/exprs.rs, re-exported fromvortex_array::expr. It returns an error for an empty pair list and for more thanu32::MAXpairs.nested_case_whennow delegates to it and callsvortex_expect, the same pattern thebound_*constructors use, so its behaviour for valid input is unchanged and it still panics on invalid input. Its docs now point to the fallible variant.scalar_fn/fns/case_when.rs: the empty case returns an error (with and without ELSE), the fallible constructor builds the same expression asnested_case_when, andnested_case_whenstill panics on empty input. Plus a doctest ontry_nested_case_when.bound_nested_case_whenis left as is; happy to add a fallible bound variant too if you want one.Tested with
cargo test -p vortex-array --lib case_when(80 passed), the new doctest,cargo clippy -p vortex-array --all-targets --all-features -- -D warnings(clean) andcargo +nightly fmt --all --check.AI assistance: this change was prepared with help from an AI coding assistant (agentic), and reviewed and submitted by me.